<!---
    |----------------------------------------------------------------------------------------------|
	| Parameter  | Required | Type    | Default | Description                                      |
    |----------------------------------------------------------------------------------------------|
	| name       | Yes      | string  |         | table name, in pluralized form                   |
	| force      | No       | boolean | false   | drop existing table of same name before creating |
	| id         | No       | boolean | true    | if false, defines a table with no primary key    |
	| primaryKey | No       | string  | id      | overrides default primary key name
    |----------------------------------------------------------------------------------------------|

    EXAMPLE:
      t = createTable(name='employees',force=false,id=true,primaryKey='empId');
      t.string(columnNames='name', default='', null=true, limit='255');
      t.text(columnNames='bio', default='', null=true);
      t.time(columnNames='lunchStarts', default='', null=true);
      t.datetime(columnNames='employmentStarted', default='', null=true);
      t.integer(columnNames='age', default='', null=true, limit='1');
      t.decimal(columnNames='hourlyWage', default='', null=true, precision='1', scale='2');
      t.date(columnNames='dateOfBirth', default='', null=true);
--->
<cfcomponent extends="raihan.plugins.dbmigrate.Migration" hint="install">
	<cffunction name="up">
		<cfscript>
			// settings
			t = createTable(name='settings', force='true');
			t.string(columnNames='settingname,settingvalue', null='true', limit='100');
			t.timestamps();
			t.create();
			// is already installed
			addRecord(table='settings', settingname='installed', settingvalue='false');
						
			// companies
			t = createTable(name='companies', force='true');
			t.string(columnNames='companyname', null='false', limit='200');
			t.string(columnNames='address', null='true', limit='1000');
			t.string(columnNames='phone,fax', null='true', limit='50');	  
			t.timestamps();
			t.create();
			
			// organizations
			t = createTable(name='organizations', force='true');
			t.string(columnNames="organizationname", null='false');
			t.references(referenceNames='company', foreignKey='true');
			t.timestamps();
			t.create();
			
			// grades
			t = createTable(name='grades', force='true');
			t.string(columnNames='gradename', null='false');
			t.references(referenceNames='company', foreignKey='true');
			t.timestamps();
			t.create();
			
			// users
			t = createTable(name='users', force='true');      
			t.string(columnNames='username', null='false', limit='50');
			t.string(columnNames='userpassword', null='false', limit='128');
			t.string(columnNames='isadmin,userstatus,crosscompany', null='false', limit='1');			
			t.timestamp(columnNames='lastlogin', null='true');
			t.timestamps();
			t.create();
			
			// user roles
			t = createTable(name='userroles', force='true');
			t.references(referenceNames='user', foreignKey='true');
			t.string(columnNames='role', null='false', limit='200');
			t.timestamps();
			t.create();
			
			// people
			t = createTable(name='people', force='true');
			t.string(columnNames='firstname', null='false', limit='50');
			t.string(columnNames='middlename,lastname', null='true', limit='50');
			t.string(columnNames='idcard', null='true', limit='50');
			t.string(columnNames='birthplace', null='true', limit='100');
			t.timestamp(columnNames='birthdate', null='true');
			t.string(columnNames='maritalstatus', null='true', limit='20');
			t.references(referenceNames='user', foreignKey='true');
			t.timestamps();
			t.create();
			
			// employee
			t = createTable(name='employees', force='true');
			t.timestamp(columnNames='startdate', null='false');
			t.timestamp(columnNames='enddate', null='true');
			t.references(referenceNames='person,company,organization,grade', foreignKey='true');			
			t.timestamps();
			t.create(); 
		</cfscript>
	</cffunction>
	
	<cffunction name="down">
		<cfscript>
			dropTable('settings');
			dropTable('employees');
			dropTable('organizations');
			dropTable('grades');
			dropTable('companies');						
			dropTable('userroles');
			dropTable('people');
			dropTable('users');
		</cfscript>
	</cffunction>
</cfcomponent>